package com.source.thread.bb;



class Ticket {
    private   int  ticketNum=100;



    public synchronized  void sell()     {  // public synchronized void sell()

               while(ticketNum>0){
                   System.out.println("当前的线程名称："+Thread.currentThread().getName()+"--"+ticketNum);

                   ticketNum--;
               }



    }


  /*  public   void sell() {  // public synchronized void sell()
        lock.lock();
        try{
            while (flag){
                if(ticketNum>0){
                    System.out.println("当前的线程名称："+Thread.currentThread().getName()+"--"+ticketNum);
                    ticketNum--;
                }else{
                    flag=false;

                }

            }
        }catch(Exception e){
            System.out.println(e.getMessage());
        }finally {
            lock.unlock();
        }
    }*/
}
